
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

class DioHttpDemo extends StatelessWidget {
  const DioHttpDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: ElevatedButton(
          child: Text('发送HTTP请求'),
          onPressed: () {
            print('http request sending ...');
            getIpAddressInfo();
          },
        ),
      ),
    );
  }

  void getIpAddressInfo() async {
    try {
      final String url = 'http://httpbin.org/ip';
      Response response = await Dio().get(url);
      print('response.data -> ${response.data}');
    } catch (error) {
      print('error -> ${error}');
    }
  }

}